<div style="border: 1px solid black; border-radius: 5px; margin: 5px 10px 10px 0px; background-color: white;">
    <div class="money">
        <div class="t">账号余额：</div>
        <div class="value">0.00</div>
        <div class="t" style="margin-left: 40px;">未结余额：</div>
        <div class="value">0.00</div>
        <div class="clear"></div>
    </div>

    <div>
        <form action="#" class="am-form am-form-horizontal take" onsubmit="return false">
            <fieldset>
                <table>
                    <tr>
                        <td class="label">取款用户：</td>
                        <td class="field">
                            <input type="text" class="am-form-field" name="account" disabled/>
                        </td>
                        <td class="copy"> </td>
                    </tr>
                    <tr>
                        <td class="label">可用提款额度：</td>
                        <td class="field">
                            <input type="text" class="am-form-field" name="balance" disabled/>
                        </td>
                        <td class="copy"> </td>
                    </tr>
                    <tr>
                        <td class="label">提款人姓名：</td>
                        <td class="field">
                            <input type="text" class="am-form-field" name="realname" disabled/>
                        </td>
                        <td class="copy"> </td>
                    </tr>
                    <tr>
                        <td class="label">提款银行：</td>
                        <td class="field">
                            <input type="text" class="am-form-field" name="bank" disabled/>
                        </td>
                        <td class="copy"> </td>
                    </tr>
                    <tr>
                        <td class="label">提款银行地址：</td>
                        <td class="field">
                            <input type="text" class="am-form-field" name="addr" disabled/>
                        </td>
                        <td class="copy"> </td>
                    </tr>
                    <tr>
                        <td class="label">提款金额：</td>
                        <td class="field">
                            <input type="number" name="amount" min="1" max="100000"
                                placeholder="请输入提款金额，单位：元。" class="am-form-field" required/>
                            <div class="input-clue">单笔限额：100 ~ 100,000</div>
                        </td>
                        <td class="copy"> </td>
                    </tr>
                    <tr>
                        <td class="label">提款密码：</td>
                        <td class="field">
                            <input type="password" name="password" 
                                placeholder="请输入提款密码" class="am-form-field"/>
                        </td>
                        <td class="copy"> </td>
                    </tr>
                </table>

                <button class="btn" type="submit">提交申请</button> 
            </fieldset>
        </form>
    </div>
</div>

<style type="text/css">
    .money {
        background-color: #ffd946;
        color: black;
        font-size: 16px;
        padding: 8px;
        border-bottom: 1px solid black;
    }
    .money .t {
        float: left;
    }
    .money .value {
        float: left;
        color: red;
        font-weight: bold;
        background-color: white;
        border: 1px solid white;
        border-radius: 3px;
        padding: 5px;
        min-width: 100px;
        line-height: 18px;
        margin-left: 5px;
    }
    .am-selected {
        width: 100%;
    }

    .am-form .btn {
        margin-left: 200px;
    }
</style>

<script>
    // 刷新账号信息
    var bankInfo = {};
    ME.query(function() {
        var arr = $(".money .value");
        arr.html(context.user.balance/100);
        $(arr[1]).html(context.user.pending/100);

        if (context.user.user.bank && context.user.user.bank != '') {
            bankInfo = JSON.parse(context.user.user.bank);
            $("input[name='bank']").val(bankInfo.bank);
            $("input[name='addr']").val(bankInfo.addr);
        }
        else {
            $("#clue .btn").click(function() {
                
                Util.jumpUrl({
                    n1: '会员专区',
                    n2: '我的银行卡'
                });
            });
            alert2("请先绑定银行卡信息！", true);
        }

        $("input[name='realname']").val(context.user.user.name || '');
        $("input[name='balance']").val(context.user.balance/100);
        $("input[name='account']").val(context.user.user.mobile || '游客');
    });

    $(".take button.btn").click(function() {
        if (!bankInfo) {
            alert2("请先绑定银行卡信息！", true);
            return;
        }

        var amount = $("input[name='amount']").val();
        if (amount == '') return;
        amount = parseInt(amount);
        if (amount < 100 || amount > 100000) return;

        if (context.user.dw > 0) {
            alert2("您的投注额度尚未达到要求，暂时无法取款！", true);
            return;
        }
        if (context.user.balance < amount * 100) {
            alert2("余额不足！", true);
            return;
        }

        // 检测取款密码
        var p = $("input[name='password']").val();
        if (p != context.user.user.password && context.user.user.password) {
            alert2("取款密码验证失败！", true);
            return;
        }

        var memo = {
            bank: v.bank,
            addr: v.addr,
            account: v.account,
        }
        startLoading();
        CMD.withdraw(context.user.user.id, "", amount*100, memo, function() {
            stopLoading();
            alert2("提交成功！");
            ME.query();
        }, function(message) {
            stopLoading();
            alert2("提交失败，错误原因：" + message, true);
            ME.query();
        });
    });
</script>